package com.sevenGroup.pawnshop.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sevenGroup.pawnshop.controller.form.ShopSelectConditionalForm;
import com.sevenGroup.pawnshop.model.Goods;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
public interface GoodsDao extends BaseMapper<Goods> {
//  根据条件查询商品（门店ID，仓库ID，商品大类ID，小类ID，商品ID等）
    @Select("<script> select * from goods where 1=1" +
            "<if test=\"scf.storeId != null\"> and store_id=#{scf.storeId} </if>" +
            "<if test=\"scf.firstTypeId != null\"> and store_id=#{scf.firstTypeId} </if>" +
            "<if test=\"scf.secondTypeId != null\"> and store_id=#{scf.secondTypeId} </if>" +
            "<if test=\"scf.warehouseId != null\"> and store_id=#{scf.warehouseId} </if>" +
            "<if test=\"scf.goodId != null\"> and store_id=#{scf.goodId} </if>" +
            "<if test=\"scf.brandId != null\"> and store_id=#{scf.brandId} </if>" +
            "ORDER BY purchase_time DESC </script>")
    @Results(id = "",value = {
            @Result(column = "good_id",property = "goodId"),
            @Result(column = "good_name",property = "goodName"),
            @Result(column = "good_describe",property = "goodDescribe"),
            @Result(column = "good_second_Type_id",property = "goodSecondTypeId"),
            @Result(column = "good_second_Type",property = "goodSecondType"),
            @Result(column = "brand_id",property = "brandId"),
            @Result(column = "brand_name",property = "brandName"),
            @Result(column = "store_id",property = "storeId"),
            @Result(column = "store_name",property = "storeName"),
            @Result(column = "warehouse_id",property = "warehouseId"),
            @Result(column = "warehouse_name",property = "warehouseName"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "user_name",property = "userName"),
            @Result(column = "submit_time",property = "submitTime"),
            @Result(column = "purchase_time",property = "purchaseTime"),
            @Result(column = "first_purchase_price",property = "firstPurchasePrice"),
            @Result(column = "good_properties",property = "goodProperties"),
            @Result(column = "good_ldentification_figure",property = "goodLdentificationFigure")
    })
    IPage<Goods> selectShopsByConditionals(Page page, @Param("scf") ShopSelectConditionalForm selectConditionalForm);
//  改变商品评估鉴定状态
    @Update("update goods set good_state=#{goodState} where good_id=#{goodId}")
    void updateGoodState(@Param("goodId") Integer goodId, @Param("goodState") String goodState);
}
